﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - TaskTimeTable" 
*/ 

component 
	displayname="public.service.db.senate.sequence.TaskTimeTable" 
	output=false 
	accessors=true 
	{
		
	property type="string" name="TaskID" hint="教学任务号";
	property type="string" name="TimeIndex" hint="时间序列";

	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "生成排课时间序号"
	* 
	* @TaskArrange "排课教学任务"
	*/
	public string function getTimeIDX() output=false {
		
		/* 
			排课时间序号规则 3位代码
		*/
		var nextID = numberFormat(1, "0__");
		
		var sql = "	SELECT tidx FROM t_task_timetable WHERE task_id = :taskId ORDER BY tidx DESC ";
						  
		var queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		queryObj.addParam( name="taskId", value=getTaskID(), cfsqltype="cf_sql_varchar" );;	
		var rs_check = queryObj.execute( sql=sql ).getResult();
		
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = numberFormat((rs_check.tidx + 1), "0__");
		}

		return nextID;
		
	}

	/**
	* @hint "自定义主键规则"
	* 
	* @TaskArrange "排课教学任务"
	* @TimeIndex "上课时间序列"
	*/
	public string function getID() output=false {

		var nextID = getTaskID() & "," & getTimeIndex();

		/* 
			主键生成规则 
			
			教学班上课时间编号22位 18位教学任务号 , 3位时间序号

			Unique: TASK_ID, TIDX
		*/
		return nextID;
	}

}

</cfscript>